<?php

class userComponents extends sfComponents
{

    public function executeSelect_currency()
    {
        $returnUrl = $this->getModuleName() . '/' . $this->getActionName();
        if( ($id = (int)$this->getRequestParameter('id', 0)) )
        {
            $returnUrl .= '?id=' . $id;
        }
        // TODO: move to system module
        $this->setFlash('returnUrl',$returnUrl);
    }
    
    public function executeRole()
    {
        $this->arRoles = MyConstants::getRolesList();
        $arUserRoles = explode(':', $this->user->getRoles());
        $totalR = count($arUserRoles);
        $ar = array();
        for($i = 0; $i < $totalR; $i++)
            $ar[$arUserRoles[$i]] = 1;

        $this->userRoles = $ar;
    }

	public function executeMedics() 
	{
	    $this->arRoles = MyConstants::getRolesList();
		$docs = array();
		$users = UserPeer::doSelect(new Criteria());
		foreach( $users as $user )
		{
		    $arRoles = explode(':', $user->getRoles());
			if( in_array(MyConstants::ROLE_MEDIC_DIETITIAN, $arRoles) || in_array(MyConstants::ROLE_MEDIC_PSYCHO, $arRoles) || in_array(MyConstants::ROLE_MEDIC_THERAPIST, $arRoles) ) 
			{
			    $docs[] = $user;
			}
		}
		$this->docs = $docs;
	}

}
